package com.golxen.framework.activity.dao;


import com.golxen.framework.db.DBManager;
import com.golxen.framework.db.dao.AbstractDaoImpl;

import java.sql.CallableStatement;
import java.sql.ResultSet;
import java.util.HashMap;
import java.util.Map;

public class CrossActivityProcessDaoImpl extends AbstractDaoImpl {
    public Map<Integer,Integer> getAllActivityCrossInfo() {
        ResultSet rs = null;
        CallableStatement call = null;
        Map<Integer, Integer> dataMap = new HashMap<>();

        String sql = "select activityId,crossServerId from t_s_activity_main";
        try {
            getDb().setConnName(DBManager.serverDbName);
            call = getDb().getConnection().prepareCall(sql);
            rs = call.executeQuery();
            while (rs.next()) {
                int activityId = rs.getInt("activityId");
                int crossId = rs.getInt("crossServerId");
                dataMap.put(activityId, crossId);
            }
        } catch (Exception e) {
            throw new RuntimeException(e);
        } finally {
            getDb().closeConnection(call, rs);
        }
        return dataMap;
    }

    public Map<Integer,Integer> getActivityCrossInfo(int id) {
        ResultSet rs = null;
        CallableStatement call = null;
        Map<Integer, Integer> dataMap = new HashMap<>();

        String sql = "select activityId,crossServerId from t_s_activity_main where activityId = ?";
        try {
            getDb().setConnName(DBManager.serverDbName);
            call = getDb().getConnection().prepareCall(sql);
            call.setInt(1,id);
            rs = call.executeQuery();
            while (rs.next()) {
                int activityId = rs.getInt("activityId");
                int crossId = rs.getInt("crossServerId");
                dataMap.put(activityId, crossId);
            }
        } catch (Exception e) {
            throw new RuntimeException(e);
        } finally {
            getDb().closeConnection(call, rs);
        }
        return dataMap;
    }


}
